package cn.edu.zjut.medlinebackend.service.impl;

import cn.edu.zjut.medlinebackend.model.Favorite;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.edu.zjut.medlinebackend.service.FavoriteService;
import cn.edu.zjut.medlinebackend.mapper.FavoriteMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 86182
 * @description 针对表【favorite】的数据库操作Service实现
 * @createDate 2024-01-05 15:22:45
 */
@Service
public class FavoriteServiceImpl extends ServiceImpl<FavoriteMapper, Favorite>
        implements FavoriteService {

    @Resource
    private FavoriteMapper favoritesMapper;

    @Override
    public boolean favoriteFile(String fileName, Integer userId) {
        Favorite favorite = new Favorite();
        favorite.setUserId(userId);
        favorite.setFileName(fileName);
        favorite.setIsdelete(0);
        int insert = favoritesMapper.insert(favorite);
        return insert > 0;
    }

    public boolean deleteFavoriteFile(String fileName, Integer userId) {
        return favoritesMapper.deleteFavoriteFile(fileName, userId);
    }

    public boolean seleteFavoriteFile(String fileName, Integer userId) {
        Favorite favorite = favoritesMapper.seleteFavoriteFile(fileName, userId);
        return favorite != null;
    }

}




